package org.springblade.tms.module.userinfo.controller;

import cn.hutool.crypto.SecureUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.system.user.feign.IUserClient;
import org.springblade.tms.module.userinfo.dto.ChangePasswordDto;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @projectName: BladeX
 * @package: org.springblade.tms.module.userinfo.controller
 * @className: AppletsController
 * @author: yr
 * @description: 小程序用户相关接口
 * @date: 2022/3/14 16:46
 */
@RestController
@RequestMapping("userInfo/applets")
@Api(value = "小程序用户相关接口-yr", tags = "小程序用户相关接口-yr")
public class AppletsController {
	@Resource
	private IUserClient userClient;

	/**
	 * @param changePasswordDto
	 * @return R
	 * @author yr
	 * @description 修改密码
	 * @date 2022/3/9 11:48
	 */
	@ApiLog("修改密码")
	@PostMapping("/updatePassword")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "修改密码", notes = "传入car")
	@PreAuth("hasAnyRole('admin','administrator','carrier','driver')")
	public R updatePassword(@RequestBody ChangePasswordDto changePasswordDto) {
		String md5 = SecureUtil.md5(changePasswordDto.getNewPassword());
		return userClient.updatePassword(changePasswordDto.getParentId(),md5);
	}
}
